package com.cy.mall.service.wj.impl;

import com.cy.mall.dao.mapper.wj.WsOrderMapper;
import com.cy.mall.model.Result;
import com.cy.mall.model.ao.wj.WsOrderAddAO;
import com.cy.mall.model.ao.wj.WsOrderEditAO;
import com.cy.mall.model.domain.wj.WsOrder;
import com.cy.mall.service.BaseService;
import com.cy.mall.service.wj.WsOrderService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @Description 万税贷询单 service
 * @Author tanyilin
 * @Date 2019/6/6 14:36
 */
@Service
public class WsOrderServiceImpl extends BaseService implements WsOrderService {

    @Autowired
    private WsOrderMapper wsOrderMapper;

    @Override
    @Transactional
    public Result addWsOrder(WsOrderAddAO addAO, Long customerId) {

        Date time = new Date();
        Long wsOrderId = null;

        //新增万税贷询单
        WsOrder newWsOrder = new WsOrder();
        BeanUtils.copyProperties(addAO, newWsOrder);
        newWsOrder.setCustomerId(customerId);
        newWsOrder.setCreateTime(time);
        newWsOrder.setUpdateTime(time);
        wsOrderMapper.insertSelective(newWsOrder);
        wsOrderId = newWsOrder.getId();

        return Result.success("新增万税贷询单成功", wsOrderId);
    }

    @Override
    @Transactional
    public void editWsOrder(WsOrder wsOrder) {

        wsOrder.setUpdateTime(new Date());
        wsOrderMapper.updateByPrimaryKeySelective(wsOrder);
    }
}
